package edu.whu;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.junit.jupiter.api.Assertions.*;

public class MyClassTest2 {
    Class testClass = edu.whu.MyClass.class;

    @Test
    public void testMethod() throws IllegalAccessException, InstantiationException{
        Object o = testClass.newInstance();

        assertFalse(((MyClass)o).init("YHY", "2131"));
        assertFalse( new MyClass().init("YHY", "YYYerttty"));
        assertTrue(new MyClass().init("YHY", "werwe34234"));
        assertFalse(new MyClass().init("YHY", "12q"));

        assertThrows(IllegalArgumentException.class, ()->{
            Object newClass = testClass.newInstance();
            Method[] methods = testClass.getMethods();
            for(Method method: methods){
                if(method.isAnnotationPresent(initMethod.class)){
                    method.invoke(newClass, "123");
                }
            }
        });
    }
}
